package com.qmth.gkwb.web.view;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.qmth.gkwb.data.document.Student;
import com.qmth.gkwb.data.repository.StudentRepo;

@Controller
@RequestMapping("view/print")
public class PrintController {

	@Autowired private StudentRepo stuRepo;
	
	@RequestMapping("{studentId}")
	public ModelAndView print(@PathVariable String studentId) {
		Student student = stuRepo.findOne(studentId);
		return new ModelAndView("print", "student", student);
	}
	
	@RequestMapping
	public ModelAndView printByExamId(@RequestParam String examId) {
		Student student = null;
		List<Student> students = stuRepo.findByExamId(examId);
		if(students.size() > 0){
			student = students.get(0);
		}
		return new ModelAndView("print", "student", student);
	}
	
	@RequestMapping(value="signpoint/batch")
	public ModelAndView printBySignPoint(@RequestParam Long xxid,@RequestParam(required=false) Long bjid){
		List<Student> students = null;
		if(bjid != null){
			students = stuRepo.findBySignPointIdAndSchoolClassId(xxid, bjid);
		}
		else{
			students = stuRepo.findBySignPointId(xxid);
		}
		return new ModelAndView("print_batch", "students", students);
	}
}
